package com.lxl.securitypermission.service.impl;

import com.lxl.securitypermission.constant.HttpCode;
import com.lxl.securitypermission.constant.StatusCode;
import com.lxl.securitypermission.dto.ResponseResult;
import com.lxl.securitypermission.entity.SUser;
import com.lxl.securitypermission.mapper.SUserMapper;
import com.lxl.securitypermission.service.UserService;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 绫小路
 * @date 2020/12/29 22:45
 * @description
 */
@Service
public class UserServiceImpl implements UserService {

  @Autowired
  private SUserMapper sUserMapper;

  @Override
  public SUser get(String username) {
    return sUserMapper.get(username);
  }


  @Override
  public ResponseResult register(String username, String password, String nickname, Integer sex) {
    SUser s = sUserMapper.get(username);
    if (s != null) {
      return new ResponseResult(HttpCode.FAIL, "账号已经被注册！请换一个");
    }
    SUser user = new SUser();
    user.setUsername(username);
    user.setPassword(password);
    user.setSex(sex);
    user.setStatus(StatusCode.VALID);
    user.setNickname(nickname);
    user.setCreateTime(new Date());
    sUserMapper.insertSelective(user);
    return new ResponseResult(HttpCode.OK, "注册成功！");
  }
}
